﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace HGZP.PLL
{
    public class OperateDataGridView
    {
        /// <summary>
        /// 统一DataGridView属性
        /// </summary>
        /// <param name="dataGridView"></param>
        public static void SetDataGridViewFormat(DataGridView dataGridView)
        {
            dataGridView.AllowUserToAddRows = false;
            dataGridView.AutoGenerateColumns = false;
            dataGridView.AlternatingRowsDefaultCellStyle.BackColor = Color.Azure;
            dataGridView.RowTemplate.Resizable = DataGridViewTriState.False;
            dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridView.EditMode = DataGridViewEditMode.EditOnEnter;
            dataGridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
            dataGridView.BorderStyle = BorderStyle.None;
            dataGridView.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
            dataGridView.RowHeadersWidth = 35;
            dataGridView.AllowUserToOrderColumns = true;
            dataGridView.RowTemplate.Height = 19;
            dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonFace;
        }

        /// <summary>
        /// 给DataGridView添加行号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void AddRowIndex(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush s = new SolidBrush(Color.Black);
            e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1), e.InheritedRowStyle.Font, s, e.RowBounds.X + 10, e.RowBounds.Y + 4);
        }
    }
}
